package workbench.actors;

import box2D.collision.shapes.B2CircleShape;
import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2BodyDef;
import box2D.dynamics.B2FixtureDef;
import box2D.dynamics.B2World;
import com.funkyfurrymonkey.world2d.Actor;
import openfl.display.Bitmap;

/**
 * ...
 * @author Marcos Martinez
 */
class Ball extends Actor
{
	private var m_physScale:Float = 1;

	public function new(cWorld:B2World, cCostume:Bitmap) 
	{
		
		
		var cd:B2CircleShape = new B2CircleShape();
		cd.m_radius = (cCostume.width/2) / m_physScale;
		var fd:B2FixtureDef = new B2FixtureDef();
		fd.density = 2;
		fd.restitution = 0.2;
		fd.friction = 0.5;
		fd.shape = cd;
		var bd:B2BodyDef = new B2BodyDef();
		bd.type = 2;//B2Body.B2_dynamicBody;
		var cData :Object2dData = new Object2dData();
		cData.name = "ball";
		bd.userData = cData;
		bd.position.set( (50 ) / m_physScale, (100 ) / m_physScale);
		
		var cBody: B2Body = cWorld.createBody(bd);
		cBody.createFixture(fd);
			
		var nX :Float = 1.0;
		var nY:Float = 1.0;
			
		var nVelX :Float = 150.0;
		var nVelY:Float = 10.0;
			
		
		var startingVelocity:B2Vec2 = new B2Vec2(nVelX, nVelY);
		cBody.m_force = new B2Vec2(100, 100);
		cBody.setLinearVelocity(startingVelocity);
		cBody.applyImpulse(new B2Vec2(nX, -1 * nY), cBody.getWorldCenter());
		cBody.setPosition(new B2Vec2(nX, nY));
		
		
		super(cBody, cCostume);
		

		var cContact:ContactListener = new ContactListener(this);
		cWorld.setContactListener(cContact);
		
	}
	
	
	override public function hits(cData:Dynamic)
	{
		
		
	}
	
}